#include<iostream>
#include<vector>
#include<unordered_map>
using namespace std;
int longestConsecutive(vector<int>& nums) {
    unordered_map<int,int>a;
    int m=0;
    for(auto x:nums){
        if(!a.count(x)){
            if(!a.count(x-1)&&!a.count(x+1))
                a[x]=1;
            else if(!a.count(x-1)&&a.count(x+1))
                a[x]=++a[x+1];
            else if(a.count(x-1)&&!a.count(x+1))
                a[x]=++a[x-1];
            else{
                a[x]=a[x-1]+a[x+1]+1;
                a[x-1]=a[x];a[x+1]=a[x];
                }
            if(m<a[x])m=a[x];
        }
    }
    cout<<m;
    return m;
}
int main(){
    vector <int> a={0,3,7,2,5,8,4,6,0,1};
    longestConsecutive(a);
}